package com.whale.flowable.listener;

import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener;
import org.flowable.engine.delegate.event.FlowableCancelledEvent;
import org.flowable.engine.delegate.event.FlowableProcessStartedEvent;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.stereotype.Component;

import java.util.HashSet;
import java.util.Set;

/**
 * 监听 {@link ProcessInstance} 的状态变更，更新其对应的 status 状态
 *
 * @author jason
 */
@Component
public class BpmProcessInstanceEventListener extends AbstractFlowableEngineEventListener {

    public static Set<FlowableEngineEventType> PROCESS_INSTANCE_EVENTS;


    static {
        PROCESS_INSTANCE_EVENTS = new HashSet<>();
        PROCESS_INSTANCE_EVENTS.add(FlowableEngineEventType.PROCESS_CANCELLED);
        PROCESS_INSTANCE_EVENTS.add(FlowableEngineEventType.PROCESS_COMPLETED);
        PROCESS_INSTANCE_EVENTS.add(FlowableEngineEventType.PROCESS_CREATED);
        PROCESS_INSTANCE_EVENTS.add(FlowableEngineEventType.PROCESS_STARTED);
    }

    public BpmProcessInstanceEventListener(){
        super(PROCESS_INSTANCE_EVENTS);
    }

    @Override
    protected void processCancelled(FlowableCancelledEvent event) {
        System.out.println("全局事件监听器启动 processCancelled---");
    }

    @Override
    protected void processCompleted(FlowableEngineEntityEvent event) {
        System.out.println("全局事件监听器启动 processCompleted---");
    }

    @Override
    protected void processCreated(FlowableEngineEntityEvent event) {
        System.out.println("全局事件监听器启动 processCreated---");
    }

    @Override
    protected void processStarted(FlowableProcessStartedEvent event) {
        System.out.println("全局事件监听器启动 processStarted---");
    }

}
